<template>
  <div>
    <el-table
      :data="list"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      :tree-props="{children: 'children'}"
    >
      <el-table-column prop="id" label="规格编号" align="center"></el-table-column>

      <el-table-column prop="specsname" label="规格名称" align="center"></el-table-column>

      <el-table-column label="规格属性" align="center">
        <template slot-scope="scope">
          <el-tag v-for="item in scope.row.attrs" :key="item"  type="info">{{item}}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <el-button type="primary" v-if="scope.row.status==1">启用</el-button>
          <el-button type="info" v-else>禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" @click="willEdit(scope.row.id)">编辑</el-button>
          <del-btn @del="del(scope.row.id)"></del-btn>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      layout="prev, pager, next"
      :total="count"
      :page-size="size"
      background
      @current-change="changePage"
    ></el-pagination>
  </div>
</template>
<script>
import {reqspecsdelete} from "../../../request/api";
import { successAlert } from "../../../utils/alert";
import { mapGetters, mapActions } from "vuex";
export default {
  components: {},

  mounted() {
    this.reqlist();
    this.reqcount()
  },
  computed: {
    ...mapGetters({
      list: "specs/list",
      count: "specs/count",
      size: "specs/size",
    }),
  },
  methods: {
    ...mapActions({
      reqlist: "specs/reqlist",
      reqcount:"specs/reqcount",
      changePage:"specs/changePage"
    }),
    //5.点击了编辑
    willEdit(id) {
      this.$emit("edit", id);
    },
    //删除
    del(id) {
      //点了确定
      reqspecsdelete({ id: id }).then((res) => {
        if (res.data.code == 200) {
          //弹成功
          successAlert(res.data.msg);

          //刷list
          this.reqlist();
          this.reqcount()
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
img {
  width: 100px;
  height: 100px;
}
</style>